home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / pc / Shout3Ddemo / Shout3d_runtime / codebase / custom_nodes / CountDisplay.java < prev    next >
Text File  |  2000-10-19  |  1KB  |  47 lines

  1. package custom_nodes;
  2.  
  3. import shout3d.core.*;
  4. import shout3d.*;
  5. import java.awt.*;
  6.  
  7.  
  8. public class CountDisplay extends PostRenderEffect implements DeviceObserver {
  9.  
  10.    boolean initialized = false;  
  11.    int count = 0; 
  12.      Font labelFont =  new Font("SansSerif", Font.BOLD, 16);
  13.       
  14.    //constructor   
  15.    public CountDisplay (){
  16.    }
  17.  
  18.    //to handle mouse input
  19.    public boolean onDeviceInput(DeviceInput di, Object userData){
  20.       MouseInput mi = (MouseInput)di;
  21.       switch (mi.which){
  22.       
  23.          case MouseInput.DOWN:
  24.             count++;
  25.             return true;
  26.             
  27.       }
  28.       return false;
  29.    }
  30.  
  31.    //called after each render;
  32.    //overriden from super class
  33.    public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight){
  34.       
  35.       //register to receive mouse events
  36.       if (!initialized) {
  37.          getViewer().getDeviceListener().addDeviceObserver(this, "MouseInput", null);
  38.          initialized = true;
  39.       }
  40.       
  41.       g.setFont(labelFont);  
  42.       g.setColor(java.awt.Color.red);
  43.       String countString = ""+count;
  44.       g.drawString(countString, 30, 30);
  45.    }
  46.    
  47. }